<?php
include_once(dirname(dirname(__FILE__))."/common/config.inc.php");
header("content-type:text/html; charset=utf-8");

class ThePage
{
	var $smarty;
	var $userRequest;
	var $css_file = "";
	var $html_title="";
	var $city_no = "";
	var $tree;

	function ThePage()
	{
		global $error_object;
		$this->tree = Factory::getItemClass('parseTree');
		$this->smarty = Factory::getSmarty();
		$this->smarty->template_dir = TPL_PATH."main/";
		$this->smarty->compile_dir = COM_PATH."main/";
		
		$this->userRequest = Factory::getBaseClass('UserRequest');
		
		//取得当前城市
		$this->city_no = $this->parse_city_id();
		

		//释放统计使用
		$this->smarty->assign('domain_name',DOMAIN_NAME);
		$this->smarty->assign('host_name',HOST_NAME);
		$this->smarty->assign('city_arr',$this->tree->get_city_arr());
		$this->smarty->assign('cur_city_no',$this->city_no);
		$this->smarty->assign("error_object",$error_object);
		$this->smarty->assign('css_path',CSS_PATH );
		$this->smarty->assign('js_path', JS_PATH);
		$this->smarty->assign('pic_path', PIC_PATH);

		//释放全局函数
		$this->smarty->register_function('make_url',"smarty_make_url");
	}
	
	//如果登录返回用户id，没登录返回""
	function check_login()
	{
		$uid = $this->userRequest->get('u_id');
		//$uid = 1;
		return $uid;
	}
	function parse_city_id()
	{
		$temp_arr = explode('.',$_SERVER['HTTP_HOST']);
		$cur_city_title = $temp_arr[0];
		$city_arr = $this->tree->get_city_arr();
		return isset($city_arr[$cur_city_title]) ? $cur_city_title : 0;
	}

	function jump_parent_url($url)
	{
		//global $error_object;
		//取得错误信息
		//$msg = $error_object->getErrorMsg($error_no);
		echo "<script>";
		//echo "alert(' {$msg} ');";
		echo "window.parent.location='{$url}';";
		echo "</script>";
		exit();
	}
}
function smarty_make_url($params)
{
	extract($params);
	//$type 为url类型

	//根据城市id列出该城市信息
	if($url_type=="list_city")
	{
		return "/list_city.php?city_no={$city_no}";
	}
	if($url_type=="show_article")
	{
		return "/show_article.php?aid={$aid}";
	}
	if($url_type=="list_category")
	{
		return "/list_category.php?cid={$cid}";
	}
}
function user_log($u_id,$action_type,$log_info,$log_type)
{
	$temp['user_log_id'] = "";
	$temp['user_id'] = $u_id;
	$temp['log_action'] = $_SERVER['REQUEST_URI'];
	$temp['action_referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] :"";
	$temp['log_time'] = time();
	$temp['log_type'] = $log_type;
	$temp['ip_address'] = getUserIP();
	$temp['log_inof'] = $log_info;
	//print_r($temp);exit();
	if(defined('USER_USE_LOG4J') && USER_USE_LOG4J)
	{
		unset($temp['user_log_id']);
		include_once(LOG4J_PATH."Logger.php");
		Logger::configure(USER_LOG4J_CONFIG);
		$logger = Logger::getLogger($action_type);
		$temp['log_inof'] = json_encode($temp['log_inof']);
		$log_msg = implode('#||#',$temp);
		$logger->debug($log_msg);
	}
}
?>